<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <meta charset="UTF-8">
    <title>更新用户</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css"
          integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
            integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
            integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"
            integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
            crossorigin="anonymous"></script>
    <style>
        .myform {
            width: 700px;
            height: 550px;
            margin: 100px auto;
        }
    </style>
</head>
<body>
<div class="myform" sec:authorize="hasAuthority('MYUSER_UPDATE')">
    <form th:action="@{/myuser/updateData}" method="post">
        <input type="hidden" th:value="${uid}" name="uid">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" name="username" th:value="${username}" disabled>
        </div>
        <div class="form-group">
            <label for="newPassword">新密码</label>
            <input type="password" class="form-control" id="newPassword" name="newPassword">
        </div>
        <div class="form-group form-check">
            <div th:each="role,roleStat : ${rolelist}">
                <input type="radio" class="form-check-input" th:id="role+${roleStat.count}" name="roles"
                       th:value="${role.getRid()}">
                <label class="form-check-label" th:for="role+${roleStat.count}"
                       th:text="${role.getDescription()}">role</label>
            </div>
        </div>
        <input type="hidden" id="rid" th:value='${rid}' name="rid">
        <button type="submit" class="btn btn-primary">提交</button>
    </form>
</div>
</body>
<script>
    var rid = $("#rid").val();
    $("input[name='roles']").each(function () {
        if ($.inArray($(this).val(), rid) >= 0) {
            $(this).attr("checked", "checked");
        }
    });
</script>
</html>